package com.pinfly.common.exception;

public class MSException extends Exception
{
    private static final long serialVersionUID = 1L;

    private String m_msg;
    private final Throwable m_origException;

    public MSException (Throwable ex, String msg)
    {
        m_msg = msg;
        m_origException = ex;
    }

    public MSException (String msg)
    {
        m_msg = msg;
        m_origException = null;
    }

    protected MSException ()
    {
        m_origException = null;
    }

    protected void setMessage (String msg)
    {
        m_msg = msg;
    }

    public Throwable getOrigException ()
    {
        return m_origException;
    }

    public String getMessage ()
    {
        if (m_msg == null)
            m_msg = "";
        StringBuffer buff = new StringBuffer (m_msg);
        if (m_origException != null)
        {
            String origMsg = m_origException.getMessage ();
            if (origMsg == null)
            {
                origMsg = m_origException.getClass ().getName ();
            }
            buff.append (" (due to " + origMsg + ")");
        }
        return buff.toString ();
    }

}
